<template>
	<view>
		 <input v-model="phoneInfo.account" placeholder="手机号"/>
		 <input placeholder="验证码" v-model="loginInfo.code"/> <button size="mini"  @click="getCode">获取验证码</button>
		<button @click="login" >登录</button>
	</view>
</template>

<script setup>
// 导入仓库
import {useAuthStore} from '@/stores/useAuthStore.js'
import {sendCode, getUserInfo,smsLogin} from '@/api/index.js'
import {ref} from 'vue'
// 使用仓库
const store = useAuthStore();
// 发送验证码需要的信息
	 const phoneInfo = ref({
		"mobileArea":"+86",
		"account":"",
		"type":2
	})
// 登录需要的信息
const loginInfo = ref({"mobileArea":"+86","mobile":"","code":"","sourceCode":601,"callback":"https://m.xgimi.com/pages/user/user"})
	function getCode(){
		sendCode(phoneInfo.value)
		.then(res=>{
			if(res.code===200){
				uni.showToast({
					title:"验证码发送到您的手机",
					icon:'none'
				})
			}
		})
	}
// 执行登录
function login(){
	// 更新mobile的值
	loginInfo.value.mobile = phoneInfo.value.account;
	// 传参一定传value值
	smsLogin(loginInfo.value)
	.then(res=>{
		if(res.code===200){
			// 存储本地数的token
			uni.setStorageSync("token",res.data.passToken)
			// 仓库去获取用户信息
			store.getUser();
			// 跳转到用户页面
			uni.switchTab({
				url:"/pages/user/user"
			})
		}
	})
}
 
	
 
 
</script>

<style>

</style>
